package org.example.myerp.service.serviceimpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.example.myerp.mapper.productDesign.productArchiveManagement.ProInformationMapper;
import org.example.myerp.pojo.PageMyself;
import org.example.myerp.pojo.*;
import org.example.myerp.service.ProInfoAssetService;
import org.example.myerp.service.ProInformationService;
import org.example.myerp.service.ProductFilesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ��Ʒ��������Ϣ�� ������ҵ��㡿ʵ����
 *
 * @author DELL
 *
 */
@Service
public class ProInformationServiceImpl implements ProInformationService {
	@Autowired
	// ��Ʒ��������Ϣ
    ProInformationMapper proInformationMapper;
	@Autowired
	// ��Ʒ��������Ϣ��ҵ��㡿
    ProInfoAssetService proInfoAssetService;
	@Autowired
	// ��Ʒ��������Ƶ�����ҵ��㡿
    ProductFilesService productFilesService;

	/**
	 * ��Ӳ�Ʒ��������Ϣ
	 */
	@Override
	public Integer getInsertProInformationMessage(ProInformation proInformation, ProInfoAsset proInfoAsset) {
		Integer row;
		// ��Ӳ�Ʒ��Ϣ����Ϣ
		row = proInformationMapper.insertProInformationMessage(proInformation);
		// proInformation.getpId()��ȡ��ǰ��ӵĲ�Ʒ��Ϣ���id
		// ��Ӳ�Ʒ��Ϣ��������Ϣ
		row += proInfoAssetService.getInsertProInfoAssetMessage(new ProInfoAsset(null, proInformation.getpId(),
				proInfoAsset.gettName(), proInfoAsset.gettId(), proInfoAsset.getYear(), proInfoAsset.getUint(),
				proInfoAsset.geteId(), proInfoAsset.getMkrList(), proInfoAsset.getProdes(), proInfoAsset.getDenjiper(),
				proInfoAsset.getTime()));
		// ��Ӳ�Ʒ��������Ƶ���
		if(proInformation.getYongType() == 1) {
			row += productFilesService.getInsertProductFilesMessage(
					new ProductFiles(null, proInformation.getpId(), null, null, null, null, null,proInformation.getPrice(), proInformation.getShiPrice()));
		}
		return row;
	}

	/**
	 * ��ѯȫ��δ���˵�ȫ����Ʒ��Ϣ
	 */
	@Override
	public PageMyself<ProInformation> getSelectAllProInformationByReviewSign(Integer pageNum, Integer pageSize) {
		// �洢�������в�������
		Map params = new HashMap<String, Object>();
		params.put("pageNum", pageNum);
		params.put("pageSize", pageSize);
		// ������ҳ�����࣬��Ϊ����ֵ
		PageMyself<ProInformation> page = new PageMyself<ProInformation>();
		if (pageNum != null && pageSize != null) {
			// ���õ�ǰҳ���ҳ��С
			page.setPageNum(pageNum);
			page.setPageSize(pageSize);
		}
		// ��ȡ��ǰҳ����
		List<ProInformation> list = proInformationMapper.selectAllProInformationByReviewSign(params);
		// ���÷�ҳ���������ʾ����
		page.setRows(list);
		// ����������
		page.setTotal(proInformationMapper.selectProInformationTotalNumber());
		return page;
	}

	/**
	 * ��ѯȫ���Ѹ��˲��Ҳ�Ʒ����Ϊ��Ʒ��ȫ����Ʒ��Ϣ������ҳ��
	 */
	@Override
	public PageMyself<ProInformation> getSelectAllProInformationByReviewSignAndyongType(Integer pageNum, Integer pageSize) {
		// �洢�������в�������
		Map params = new HashMap<String, Object>();
		params.put("pageNum", pageNum);
		params.put("pageSize", pageSize);
		// ������ҳ�����࣬��Ϊ����ֵ
		PageMyself<ProInformation> page = new PageMyself<ProInformation>();
		if (pageNum != null && pageSize != null) {
			// ���õ�ǰҳ���ҳ��С
			page.setPageNum(pageNum);
			page.setPageSize(pageSize);
		}
		// ��ȡ��ǰҳ����
		List<ProInformation> list = proInformationMapper.selectAllProInformationByReviewSignAndyongType(params);
		// ���÷�ҳ���������ʾ����
		page.setRows(list);
		// ����������
		page.setTotal(proInformationMapper.selectProInformationByHaveToReviewTotalNumber());
		return page;
	}

	/**
	 * ���ݲ�Ʒ��Ų�ѯ��Ʒ����Ϣ
	 */
	@Override
	public ProInformation getSelectProInformationByPId(Integer pId) {
		ProInformation proInformation = proInformationMapper.selectProInformationByPId(pId);
		return proInformation;
	}

	/**
	 * ��Ʒ�󸴺�ʱ�޸Ĳ�Ʒ��������Ϣ��
	 */
	@Override
	public Integer getUpdateProInformationByProInformationAll(ProInformation proInformation) {
		Integer row = proInformationMapper.updateProInformationByProInformationAll(proInformation);
		return row;
	}

	/**
	 * ��ѯ��Ʒ����Ϊ���ϵ�ȫ����Ϣ
	 */
	@Override
	public PageMyself<ProInformation> getSelectProductTypeByMaterials(Integer pageNum, Integer pageSize) {
		// �洢�������в�������
		Map params = new HashMap<String, Object>();
		params.put("pageNum", pageNum);
		params.put("pageSize", pageSize);
		// ������ҳ�����࣬��Ϊ����ֵ
		PageMyself<ProInformation> page = new PageMyself<ProInformation>();
		if (pageNum != null && pageSize != null) {
			// ���õ�ǰҳ���ҳ��С
			page.setPageNum(pageNum);
			page.setPageSize(pageSize);
		}
		// ��ȡ��ǰҳ����
		List<ProInformation> list = proInformationMapper.selectProductTypeByMaterials(params);
		// ���÷�ҳ���������ʾ����
		page.setRows(list);
		// ����������
		page.setTotal(proInformationMapper.selectProductTypeByMaterialsTotalNumber());
		return page;
	}

	/**
	 * ��Ʒ���ϼ۸����
	 */
	@Override
	public Integer getUpdateProInformation(ProInformation proInformation) {
		int row = 0;
		row += proInformationMapper.updateProInformation(proInformation);
		row += proInformationMapper.updateUnchangedPrice(proInformation.getpId());
		return row;
	}

	/**
	 * ��ѯ��Ʒ����δ�۸����
	 */
	@Override
	public List<ProInformation> getSelectMaterialGoodsUnreviewed() {
		List<ProInformation> list = proInformationMapper.selectMaterialGoodsUnreviewed();
		return list;
	}

	/**
	 *  �޸Ĳ�Ʒ��Ϣ��ļ۸����Ϊ�ѵ���
	 */
	@Override
	public Integer updateChangedPrice(Integer pId) {
		int row = proInformationMapper.updateChangedPrice(pId);
		return row;
	}
}
